<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
    <style>
        .bottom {
            width: 100%;
            position: absolute;
            top: 0px;
            left: 0px;
            height: 50px;
            line-height: 50px;
            background-color: #fff;
            border-top: 0px solid #eee;
        }
    </style>
</head>
<body>
<form class="layui-form layui-form-pane" action="" name="frmMain">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-block">
                    <input type="text" name="pwd_old" lay-verify="required" autocomplete="off" placeholder="输入旧密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="text" name="pwd_new" lay-verify="required" autocomplete="off" placeholder="输入新密码"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item ">
                <label class="layui-form-label">密码确认</label>
                <div class="layui-input-block">
                    <input type="text" name="pwd_confirm" lay-verify="required" autocomplete="off"
                           placeholder="密码确认"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="text-align: center">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                        lay-filter="save">
                    <i class="layui-icon layui-icon-ok"></i>
                    确认修改密码
                </button>
            </div>
        </div>

    </div>

</form>
<script src="../../../config/apiUrl.js"></script>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'http', 'popup', 'common', 'toast'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let http = layui.http;
        let common = layui.common;
        let toast = layui.toast;

        function closeWin() {
            let layer_index = parent.layer.getFrameIndex(window.name);
            if (layer_index > 0) {
                parent.layer.close(layer_index); //关闭当前页
            }
        }

        $(document).keyup(function (event) {
            if (event.keyCode == 27) {
                closeWin();
            }
        });

        async function updatePwd(data) {
            var return_data = await common.ajax({
                url: apiUrlConfig.user.updatePwd,
                data: data,
                type: "post",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            })
            toast.success({title: false, message: "修改成功"})
        }

        form.on('submit(save)', function (data) {
            layer.confirm('确定要修改密码么？', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                updatePwd(data.field);
            });
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
